<?php

class cartComponents extends sfComponents
{

    public function executeCart()
    {
        $userId = get_user_id();
        if( $userId > 0 )
        {   
            $this->receipt = Receipt::getOrCreateByUser($userId);
        }else 
        {
        	if( Receipt::isAnonymousCartAllowed())
        	{
        		$uid = sfContext::getInstance()->getUser()->getAttribute("anonimus_user_uid");
	            if( strlen($uid) < 1 )
	            {
	                $uid = md5(mt_rand());
	                sfContext::getInstance()->getUser()->setAttribute("anonimus_user_uid", $uid);
	            }
	            $this->receipt = Receipt::getOrCreateByAnonymousUid($uid);
        	}else 
        	{
        		$this->receipt = null;
        	}
        }
      
    }

}